<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset='utf-8'" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<title>搜索页面</title>



		<link href="css/amazeui.css" rel="stylesheet" type="text/css" />
		<link href="css/admin.css" rel="stylesheet" type="text/css" />

		<link href="css/demo.css" rel="stylesheet" type="text/css" />

		<link href="css/seastyle.css" rel="stylesheet" type="text/css" />

		<script charset="utf-8" language="javascript" type="text/javascript" src="js/jquery-1.7.min.js"></script>
		<script charset="utf-8" language="javascript" type="text/javascript" src="js/script.js"></script>
		<script charset="utf-8" language="javascript" type="text/javascript" src="js/jquery.js"></script>



		<script src="https://cdn.jsdelivr.net/npm/vue"></script>
		<script src="js/Data.js"></script>



	</head>

	<body>

		<!--顶部导航条 -->
		<div class="am-container header">
			<ul class="message-l">
				<div class="topMessage">
					<div class="menu-hd"  id="AA">
						<a href="login.html" target="_top" class="h" id="a1">亲，请登录</a>
						<a href="register.html" target="_top" id="a2">免费注册</a>
					</div>
				</div>
			</ul>
			<ul class="message-r">
				<div class="topMessage home">
					<div class="menu-hd"><a href="home2.html" target="_top" class="h">商城首页</a></div>
				</div>
				<div class="topMessage my-shangcheng">
					<div class="menu-hd MyShangcheng"><a href="#" target="_top"><i class="am-icon-user am-icon-fw"></i>个人中心</a></div>
				</div>
				<div class="topMessage mini-cart">
					<div class="menu-hd"><a id="mc-menu-hd" href="#" target="_top"><i class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong id="J_MiniCartNum" class="h">0</strong></a></div>
				</div>
				<div class="topMessage favorite">
					<div class="menu-hd"><a href="http://localhost:8080/views/shop-admin/login_admin.html" target="_top"><i class="am-icon-heart am-icon-fw"></i><span>卖家中心</span></a></div>
				</div>
				<div class="topMessage favorite">
					<div class="menu-hd"><a href="orderList.html" target="_top"><i class="am-icon-star am-icon-fw"></i><span>个人订单</span></a></div>
				</div>
			</ul>
			</div>

			<!--悬浮搜索框-->

			<div class="nav white">
				<div class="logo"><img src="images/logo.png" /></div>
				<div class="logoBig">
					<li><img src="images/logobig.png" /></li>
				</div>

				<div class="search-bar pr">
					<a name="index_none_header_sysc" href="#"></a>
					<form>
						<input id="searchInput" name="searchKeywords" type="text" placeholder="搜索" autocomplete="off">
						<input id="ai-topsearch" class="submit am-btn"  value="搜索" index="1" type="button" >
					</form>
				</div>
			</div>

			<div class="clear"></div>
			<b class="line"></b>
           <div class="search">
			<div class="search-list">
			<div class="nav-table">
					   <div class="long-title"><span class="all-goods">全部分类</span></div>
					   <div class="nav-cont">
							<ul>
								<li class="index"><a href="#">首页</a></li>
                                <li class="qc"><a href="#">闪购</a></li>
                                <li class="qc"><a href="#">限时抢</a></li>
                                <li class="qc"><a href="#">团购</a></li>
                                <li class="qc last"><a href="#">大包装</a></li>
							</ul>
						    <div class="nav-extra">
						    	<i class="am-icon-user-secret am-icon-md nav-user"></i><b></b>我的福利
						    	<i class="am-icon-angle-right" style="padding-left: 10px;"></i>
						    </div>
						</div>
			</div>
			
				
					<div class="am-g am-g-fixed">
						<div class="am-u-sm-12 am-u-md-12">
	                  	<div class="theme-popover">
							<ul class="select">
								<p class="title font-normal">
									<span class="fl">松子</span>
									<span class="total fl">搜索到<strong class="num">997</strong>件相关商品</span>
								</p>
								<div class="clear"></div>
								<div class="clear"></div>
								<li class="select-list">
									<dl id="select1">
										<dt class="am-badge am-round">分类</dt>
									
										 <div class="dd-conent" id="classification">
											<dd class="selected"><a href="#">全部</a></dd>
											<dd><a href="#">手机</a></dd>
											<dd><a href="#">笔记本</a></dd>
											<dd><a href="#">电视</a></dd>
											<dd><a href="#">游戏机</a></dd>
											<dd><a href="#">游戏本</a></dd>
										 </div>
						
									</dl>
								</li>
							</ul>
							<div class="clear"></div>
                        </div>
							<div class="search-content" style="width: 100%">
								<div class="sort" id="goodsSort">
									<li class="first"><a title="综合" href="#">综合排序</a></li>
									<li><a title="销量" href="#">销量排序</a></li>
									<li><a title="价格" href="#">价格升序</a></li>
									<li><a title="价格" href="#">价格降序</a></li>
								</div>
								<div class="clear"></div>




								<ul id="showGoodslistArea" class="am-avg-sm-2 am-avg-md-3 am-avg-lg-4 boxes">

									<p>请搜索</p>
<!--									<li v-for="goods in goodsList">-->
<!--										<div class="i-pic limit">-->
<!--											<img :src="goods.imageUrl" />-->
<!--											<p class="title fl">{{goods.name}}</p>-->
<!--											<p class="price fl">-->
<!--												<b>¥</b>-->
<!--												<strong>{{goods.price}}</strong>-->
<!--											</p>-->
<!--											<p class="number fl">-->
<!--												销量<span>{{goods.number}}</span>-->
<!--											</p>-->
<!--										</div>-->
<!--									</li>-->

								</ul>





							</div>
							<div class="clear"></div>
							<!--分页 -->
							<ul class="am-pagination am-pagination-right" id="paging">
<!--								<li class="am-disabled"><a href="#">&laquo;</a></li>-->
<!--								<li class="am-active"><a href="#">1</a></li>-->
<!--								<li><a href="#">2</a></li>-->
<!--								<li><a href="#">3</a></li>-->
<!--								<li><a href="#">4</a></li>-->
<!--								<li><a href="#">5</a></li>-->
<!--								<li><a href="#">&raquo;</a></li>-->
							</ul>

						</div>
					</div>
					<div class="footer">
						<div class="footer-hd">
							<p>
								<b>|</b>
								<a href="# ">商城首页</a>
								<b>|</b>
								<a href="# ">支付宝</a>
								<b>|</b>
								<a href="# ">物流</a>
							</p>
						</div>
						<div class="footer-bd ">
							<p>
								<a href="# ">合作伙伴</a>
								<a href="# ">联系我们</a>
								<a href="# ">网站地图</a>
							</p>
						</div>
					</div>
				</div>

			</div>

		<!--引导 -->
		<div class="navCir">
			<li><a href="home2.html"><i class="am-icon-home "></i>首页</a></li>
			<li><a href="sort.html"><i class="am-icon-list"></i>分类</a></li>
			<li><a href="shopcart.html"><i class="am-icon-shopping-basket"></i>购物车</a></li>	
			<li><a href="../person/index.html"><i class="am-icon-user"></i>我的</a></li>					
		</div>

		<!--菜单 -->
		<div class=tip>
			<div id="sidebar">
				<div id="wrap">
					<div id="prof" class="item">
						<a href="#">
							<span class="setting"></span>
						</a>
						<div class="ibar_login_box status_login">
							<div class="avatar_box">
								<p class="avatar_imgbox"><img src="images/no-img_mid_.jpg" /></p>
								<ul class="user_info">
									<li>用户名：sl1903</li>
									<li>级&nbsp;别：普通会员</li>
								</ul>
							</div>
							<div class="login_btnbox">
								<a href="#" class="login_order">我的订单</a>
								<a href="#" class="login_favorite">我的收藏</a>
							</div>
							<i class="icon_arrow_white"></i>
						</div>

					</div>
					<div id="shopCart" class="item">
						<a href="#">
							<span class="message"></span>
						</a>
						<p>
							购物车
						</p>
						<p class="cart_num">0</p>
					</div>
					<div id="asset" class="item">
						<a href="#">
							<span class="view"></span>
						</a>
						<div class="mp_tooltip">
							我的资产
							<i class="icon_arrow_right_black"></i>
						</div>
					</div>

					<div id="foot" class="item">
						<a href="#">
							<span class="zuji"></span>
						</a>
						<div class="mp_tooltip">
							我的足迹
							<i class="icon_arrow_right_black"></i>
						</div>
					</div>

					<div id="brand" class="item">
						<a href="#">
							<span class="wdsc"><img src="images/wdsc.png" /></span>
						</a>
						<div class="mp_tooltip">
							我的收藏
							<i class="icon_arrow_right_black"></i>
						</div>
					</div>

					<div id="broadcast" class="item">
						<a href="#">
							<span class="chongzhi"><img src="images/chongzhi.png" /></span>
						</a>
						<div class="mp_tooltip">
							我要充值
							<i class="icon_arrow_right_black"></i>
						</div>
					</div>

					<div class="quick_toggle">
						<li class="qtitem">
							<a href="#"><span class="kfzx"></span></a>
							<div class="mp_tooltip">客服中心<i class="icon_arrow_right_black"></i></div>
						</li>
						<!--二维码 -->
						<li class="qtitem">
							<a href="#none"><span class="mpbtn_qrcode"></span></a>
							<div class="mp_qrcode" style="display:none;"><img src="images/weixin_code_145.png" /><i class="icon_arrow_white"></i></div>
						</li>
						<li class="qtitem">
							<a href="#top" class="return_top"><span class="top"></span></a>
						</li>
					</div>

					<!--回到顶部 -->
					<div id="quick_links_pop" class="quick_links_pop hide"></div>

				</div>

			</div>
			<div id="prof-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					我
				</div>
			</div>
			<div id="shopCart-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					购物车
				</div>
			</div>
			<div id="asset-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					资产
				</div>

				<div class="ia-head-list">
					<a href="#" target="_blank" class="pl">
						<div class="num">0</div>
						<div class="text">优惠券</div>
					</a>
					<a href="#" target="_blank" class="pl">
						<div class="num">0</div>
						<div class="text">红包</div>
					</a>
					<a href="#" target="_blank" class="pl money">
						<div class="num">￥0</div>
						<div class="text">余额</div>
					</a>
				</div>

			</div>
			<div id="foot-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					足迹
				</div>
			</div>
			<div id="brand-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					收藏
				</div>
			</div>
			<div id="broadcast-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					充值
				</div>
			</div>
		</div>
		<script>
			window.jQuery || document.write('<script charset="utf-8" language="javascript" type="text/javascript" src="js/jquery-1.9.min.js"><\/script>');
		</script>
		<script charset="utf-8" language="javascript" type="text/javascript" src="js/quick_links.js"></script>

<div class="theme-popover-mask"></div>

	</body>

</html>


<script charset="gb2312" language="javascript" type="text/javascript">



	// let a = [1,2,3,4,5]
	// let numbers = a.splice(5);
	// console.log(numbers)
	//
	// $("#ai-topsearch").click(function () {
	// 	let searchKeywords = $("#searchInput").serialize();
	//
	//
	// 	new Vue({
	// 		el: '#showGoodslistArea',
	// 		data: {
	// 			goodsList: ""
	// 		},
	// 		methods: {
	// 			refreshSellerList: function () {
	// 				let thisObj = this
	// 				searchGoodsList(searchKeywords,thisObj)
	// 				console.log(this.goodsList)
	// 			}
	//
	// 		},
	// 		mounted: function () {
	// 			this.refreshSellerList();
	// 		},
	// 	});
	//
	// });
	//
	//
	//
	//
	// function searchGoodsList(searchKeywords,thisObj) {
	// 	$.ajax({
	// 		async: false,
	// 		type: "get",
	// 		url: "http://localhost:8080/goodsSearch",
	// 		data_type: JSON,
	// 		data: searchKeywords,
	// 		success: function (data) {
	// 			let parse = JSON.parse(data);
	// 			thisObj.goodsList = parse.data
	// 		}
	// 	})
	// }


























	window.onload=function(){
		let href = location.href;
		let strings = href.split("?");
		let decodeURI1 = decodeURI(strings[1]);

		if (decodeURI1!="undefined"){
			//获取搜索关键字
			let searchInput = document.getElementById("searchInput");

			searchInput.value = decodeURI1;

			//获取搜索关键字
			let searchKeywords = $("#searchInput").serialize();

			console.log(searchKeywords)
			//获取商品数据

			searchGoodsList(searchKeywords);
		}






	}

	classificationBindingClick()
	goodsSortBindingClick()

	//用来存放商品数据
	var defaultGoodsList = new Array();

	var array = new Array();

	var sortArray = new Array();

	var pagingArray = new Array();



	//搜索按钮事件
	$("#ai-topsearch").click(function () {

		//获取搜索关键字
		let searchKeywords = $("#searchInput").serialize();

		//获取商品数据
		searchGoodsList(searchKeywords);



	});





	//Ajax请求,搜索数据
	function searchGoodsList(parameters) {
		$.ajax({
			async: "true",
			type: "get",
			url: "http://localhost:8080/shop_api/goodsSearch",
			data_type: JSON,
			data: parameters,
			success: function (data) {
				let parse = JSON.parse(data);
				defaultGoodsList = parse.data;
				if (parse.code==0){
					alert(parse.msg)
				}
				//分类选择监听,展示选择的分类商品
				classificationSelectedListens()
				//排序监听
				goodsSortFirstListens()
				//分页
				paging()



			}
		})
	}

	//展示数据到页面上
	function showGoodsList(array) {
		let showGoodslistArea = $("#showGoodslistArea");
		showGoodslistArea.text("")
		array.forEach(goods =>{
			 showGoodslistArea.append("<li id=\'"+goods.id+"\' ><div class=\"i-pic limit\"><img src=\""+goods.imgUrl+"\" /><p class=\"title fl\">"+goods.goodsName+"</p><p class=\"price fl\"><b>¥</b><strong>"+goods.price+"</strong></p><p class=\"number fl\">销量<span>"+goods.count+"</span></p></div></li>");
		});

		if (array.length==0){
			showGoodslistArea.append("没有")
		}
		//为li绑定点击事件
		liBindingClick()
	};

	//为li绑定点击事件
	function liBindingClick(){
		let showGoodslistArea = document.getElementById("showGoodslistArea");

		let showGoodslistAreaLi = showGoodslistArea.getElementsByTagName("li");

		for (let i = 0; i < showGoodslistAreaLi.length; i++) {
			showGoodslistAreaLi.item(i).onclick = function () {
				let goodsId = showGoodslistAreaLi.item(i).getAttribute("id");
				console.log(goodsId)
				//跳转到详情页,把id带过去
				let openUrl = "http://localhost:8080/views/shop/introduction.html";
				window.open(openUrl+"?id="+goodsId)


			}
		}

	}

	//为分类按钮绑定点击事件
	function classificationBindingClick() {
		let classification = document.getElementById("classification");
		let DDelements = classification.getElementsByTagName("dd");

		// let array = new Array();

		DDelements.item(0).onclick = function () {
			// searchGoodsList()
			array = arrayListSortOrder(defaultGoodsList,"id")
			showGoodsList(array)
			goodsSortFirstListens()
			paging()
		}

		DDelements.item(1).onclick = function () {
			array = searchGoodsByTypeReturnArray(defaultGoodsList,"手机");
			showGoodsList(array)
			goodsSortFirstListens()
			paging()
		}

		DDelements.item(2).onclick = function () {
			array = searchGoodsByTypeReturnArray(defaultGoodsList,"笔记本");
			showGoodsList(array)
			goodsSortFirstListens()
			paging()
		}

		DDelements.item(3).onclick = function () {
			array = searchGoodsByTypeReturnArray(defaultGoodsList,"电视");
			showGoodsList(array)
			goodsSortFirstListens()
			paging()
		}

		DDelements.item(4).onclick = function () {
			array = searchGoodsByTypeReturnArray(defaultGoodsList,"游戏机");
			showGoodsList(array)
			goodsSortFirstListens()
			paging()
		}

		DDelements.item(5).onclick = function () {
			array = searchGoodsByTypeReturnArray(defaultGoodsList,"游戏本");
			showGoodsList(array)
			goodsSortFirstListens()
			paging()
		}

	}

	//监听分类选项按钮是否被选中
	function classificationSelectedListens() {

		// let array = new Array();

		let classification = $("#classification")
		let ddList = classification.children("dd");
		for (let i = 0; i < ddList.length; i++) {
			let dd = ddList.eq(i);
			if (dd.attr("class")=="selected"){
				//调用相应的点击事件
				switch (i) {
					case 0 :
						console.log("0")
						array = arrayListSortOrder(defaultGoodsList,"id")
						break;
					case 1 :
						console.log("1")
						array = searchGoodsByTypeReturnArray(defaultGoodsList,"手机");
						break;
					case 2 :
						console.log("2")
						array = searchGoodsByTypeReturnArray(defaultGoodsList,"笔记本");
						break;
					case 3 :
						console.log("3")
						array = searchGoodsByTypeReturnArray(defaultGoodsList,"电视");
						break;
					case 4 :
						console.log("4")
						array = searchGoodsByTypeReturnArray(defaultGoodsList,"游戏机");
						break;
					case 5 :
						console.log("5")
						array = searchGoodsByTypeReturnArray(defaultGoodsList,"游戏本");
						break;
					default :
						console.log("6")
						break;
				}
			}
		}
		showGoodsList(array)
	}

	//排序按钮绑定点击事件
	function goodsSortBindingClick() {

		let goodsSort = document.getElementById("goodsSort");
		let LIelements = goodsSort.getElementsByTagName("li");

		LIelements.item(0).onclick = function () {
			for (let i = 0; i < LIelements.length; i++) {
				if (LIelements.item(i)==this){
					this.setAttribute("class","first")
				}else {
					LIelements.item(i).setAttribute("class","")
				}
			}
			//默认排序就是根据分类区分的原始排序,id是顺序
			// searchGoodsList()
			classificationSelectedListens()
			paging()
		}
		LIelements.item(1).onclick = function () {
			for (let i = 0; i < LIelements.length; i++) {
				if (LIelements.item(i)==this){
					this.setAttribute("class","first")
				}else {
					LIelements.item(i).setAttribute("class","")
				}
			}
			//根据销量降序排序
			sortArray = arrayListSortReverseOrder(array,"number");
			showGoodsList(sortArray)
			paging()
		}
		LIelements.item(2).onclick = function () {
			for (let i = 0; i < LIelements.length; i++) {
				if (LIelements.item(i)==this){
					this.setAttribute("class","first")
				}else {
					LIelements.item(i).setAttribute("class","")
				}
			}
			//根据价格升序排序
			sortArray = arrayListSortOrder(array,"price");
			showGoodsList(sortArray)
			paging()
		}
		LIelements.item(3).onclick = function () {
			for (let i = 0; i < LIelements.length; i++) {
				if (LIelements.item(i)==this){
					this.setAttribute("class","first")
				}else {
					LIelements.item(i).setAttribute("class","")
				}
			}
			//根据价格降序排序
			sortArray = arrayListSortReverseOrder(array,"price");
			showGoodsList(sortArray)
			paging()
		}
	}

	//监听排序按钮是否被选中
	function goodsSortFirstListens() {

		let goodsSort = $("#goodsSort")
		let liList = goodsSort.children("li");
		for (let i = 0; i < liList.length; i++) {
			let li = liList.eq(i);
			if (li.attr("class")=="first"){
				//调用相应的点击事件
				switch (i) {
					case 0 :
						sortArray = array;
							return
						break;
					case 1 :
						sortArray = arrayListSortReverseOrder(array,"number");
						break;
					case 2 :
						sortArray = arrayListSortOrder(array,"price");
						break;
					case 3 :
						sortArray = arrayListSortReverseOrder(array,"price");
						break;
					default :
						break;
				}
			}
		}
		showGoodsList(sortArray)
	}

	//分页功能
	function paging() {
		let pagingArrayNumber = Math.ceil(sortArray.length/20);
		pagingArray = new Array(pagingArrayNumber);
		let number = 0;
		let pagingGoodsNumber = 0;
		for (let i = 0; i < pagingArray.length; i++) {
			let array1 = new Array();
			for (let j = 0; j < 20; j++) {
				if (number==sortArray.length){
					break
				}
				array1.push(sortArray[number])
				number++
			}
			pagingArray[i] = array1
		}

		//往页面上写分页按钮
		// <!--								<li class="am-active"><a href="#">1</a></li>-->
		// <!--								<li><a href="#">2</a></li>-->
		// <!--								<li><a href="#">3</a></li>-->
		// <!--								<li><a href="#">4</a></li>-->
		// <!--								<li><a href="#">5</a></li>-->
		let paging = $("#paging");
		paging.text("")
		for (let i = 1; i <= pagingArray.length; i++) {
			paging.append("<li><a href=\"#\">"+i+"</a></li>")
		}

		let li = document.getElementById("paging").getElementsByTagName("li");
		li[0].setAttribute("class","am-active")

		for (let i = 0; i < li.length; i++) {
			li.item(i).onclick = function () {

				for (let i = 0; i < li.length; i++) {
					if (li.item(i)==this){
						this.setAttribute("class","am-active")
					}else {
						li.item(i).setAttribute("class","")
					}
				}

				showGoodsList(pagingArray[i])
			}
		}
		showGoodsList(pagingArray[0])




	}








	//对集合顺序排序并返回集合
	function arrayListSortOrder(array,key){
		let sortArray = array;
		sortArray.sort(
				(a, b) => {
					return (a[key] < b[key]) ? -1 : (a[key] > b[key]) ? 1 : 0
				}
		)
		return sortArray;
	}

	//对集合倒序排序并返回集合
	function arrayListSortReverseOrder(array,key){
		let sortArray = array;
		sortArray.sort(
				(a, b) => {
					return (a[key] > b[key]) ? -1 : (a[key] < b[key]) ? 1 : 0
				}
		)
		return sortArray;
	}

	//根据goods的type筛选并存进array并返回array
	function searchGoodsByTypeReturnArray(defaultGoodsList,type) {
		let array = new Array();
		defaultGoodsList.forEach(goods =>{
			if (goods.type==type){
				array.push(goods)
			}
		})
		return array;
	}


	$(function () {
		//登录之后显示 用户名
		OnDisplay();
	});








</script>